﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace RMCharGen.Model
{
    internal class Statistic
    {
        public class Statistic
        {
            private int _actual;

            public int Initial { get; set ;}
            public int Potential { get; set ;}

            public int Actual
            {
                get
                {
                    return this._actual;
                }
                set
                {
                    this._actual = value;
                    DetermineBonus();
                    DetermineDevelopmentPoints();
                }
            }

            public int DevelopmentPoints { get; private set; }
            public int NormalBonus { get; private set; }
            public int RaceBonus { get; set; }
            public int MiscellaneousBonus { get; set; }
            
            public int Total
            {
                get
                {
                    return this.NormalBonus + this.RaceBonus + this.MiscellaneousBonus;
                }
            }

            public string Code { get; private set; }
            public string Name { get; private set; }
            public StatisticType StatType { get; private set; }

            private void SetCodeAndName()
            {
                switch (this.StatType)
                {
                    case StatisticType.AG:
                        this.Code = "AG";
                        this.Name = "Agility";
                        break;
                    case StatisticType.CO:
                        this.Code = "CO";
                        this.Name = "Constitution";
                        break;
                    case StatisticType.EM:
                        this.Code = "EM";
                        this.Name = "Empathy";
                        break;
                    case StatisticType.In:
                        this.Code = "In";
                        this.Name = "Intuition";
                        break;
                    case StatisticType.Me:
                        this.Code = "Me";
                        this.Name = "Memory";
                        break;
                    case StatisticType.Pr:
                        this.Code = "Pr";
                        this.Name = "Presence";
                        break;
                    case StatisticType.Qu:
                        this.Code = "Qu";
                        this.Name = "Quickness";
                        break;
                    case StatisticType.Re:
                        this.Code = "Re";
                        this.Name = "Reasoning";
                        break;
                    case StatisticType.SD:
                        this.Code = "SD";
                        this.Name = "Self Discipline";
                        break;
                    case StatisticType.St:
                        this.Code = "St";
                        this.Name = "Strength";
                        break;
                }
            }
            private void DetermineBonus()
            {
                int bonus = 0;

                if (this._actual < 2)
                {
                    bonus = -25;
                }
                else if (this._actual == 2)
                {
                    bonus = -20;
                }
                else if (this._actual > 2 && this._actual < 5)
                {
                    bonus = -15;
                }
                else if (this._actual > 4 && this._actual < 10)
                {
                    bonus = -10;
                }
                else if (this._actual > 9 && this._actual < 25)
                {
                    bonus = -5;
                }
                else if (this._actual > 74 && this._actual < 90)
                {
                    bonus = 5;
                }
                else if (this._actual > 89 && this._actual < 95)
                {
                    bonus = 10;
                }
                else if (this._actual > 94 && this._actual < 98)
                {
                    bonus = 15;
                }
                else if (this._actual > 97 && this._actual < 100)
                {
                    bonus = 20;
                }
                else if (this._actual == 100)
                {
                    bonus = 25;
                }
                else if (this._actual == 101)
                {
                    bonus = 30;
                }
                else if (this._actual > 101)
                {
                    bonus = 35;
                }

                this.NormalBonus = bonus;

                return;
            }

            private void DetermineDevelopmentPoints()
            {
                int points = 0;

                if (this.StatType == StatisticType.CO ||
                    this.StatType == StatisticType.AG ||
                    this.StatType == StatisticType.SD ||
                    this.StatType == StatisticType.Me ||
                    this.StatType == StatisticType.Re)
                {
                    if (this._actual < 5)
                    {
                        points = 1;
                    }
                    else if (this._actual > 4 && this._actual < 15)
                    {
                        points = 2;
                    }
                    else if (this._actual > 14 && this._actual < 25)
                    {
                        points = 3;
                    }
                    else if (this._actual > 24 && this._actual < 40)
                    {
                        points = 4;
                    }
                    else if (this._actual > 39 && this._actual < 60)
                    {
                        points = 5;
                    }
                    else if (this._actual > 59 && this._actual < 75)
                    {
                        points = 6;
                    }
                    else if (this._actual > 74 && this._actual < 85)
                    {
                        points = 7;
                    }
                    else if (this._actual > 84 && this._actual < 95)
                    {
                        points = 8;
                    }
                    else if (this._actual > 94 && this._actual < 100)
                    {
                        points = 9;
                    }
                    else if (this._actual > 99 && this._actual < 102)
                    {
                        points = 10;
                    }
                    else if (this._actual > 101)
                    {
                        points = 11;
                    }
                }

                this.DevelopmentPoints = points;

                return;
            }

            public Statistic(StatisticType statType)
            {
                this.StatType = statType;
                SetCodeAndName();
                DetermineBonus();
                DetermineDevelopmentPoints();
            }
    }
}
